{% extends "bash.html" %}
{% load static %}
{% block content %}
    <!-- 登录表单 --><table class="table table-bordered table-striped text-center bg-info" id="show_number">
    <thead>
    <tr class="info">
        <th class="text-center">ID</th>
        <th class="text-center">资产编号</th>
        <th class="text-center"> 登录名称 </th>
        <th class="text-center">IP地址</th>
        <th class="text-center">MAC地址</th>
        <th class="text-center">具体位置</th>
        <th class="text-center">更新时间</th>
        <th class="text-center">操作</th>
    </tr>
    </thead>
    <tbody>
     {% for status_num in status %}
        <tr>
            <td id="{{ status_num.id }}_0">{{ status_num.id }}</td>
            <td id="{{ status_num.id }}_1">{{ status_num.it_number }}</td>
            <td id="{{ status_num.id }}_2">{{ status_num.name }}</td>
            <td id="{{ status_num.id }}_3">{{ status_num.c_network }}</td>
            <td id="{{ status_num.id }}_4">{{ status_num.mac_network }}</td>
            <td id="{{ status_num.id }}_5">{{ status_num.seat_number}}</td>
            <td id="{{ status_num.id }}_6">{{ status_num.c_time}}</td>

            <td>
                <a href="#" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#edit"data-whatever="{{ status_num.id }}" >编辑</a>
            </td>
        </tr>
    {% endfor %}
    </tbody>
</table>
    <div class="modal fade" id="edit" tabindex="-1" role="dialog" aria-labelledby="edit">
                    <div class="modal-dialog" role="document">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                <h4 class="modal-title" id="myModalLabel1">编辑</h4>
                            </div>
                            <div class="modal-body">
                               <div>
                                   <div>
                                        <label><span>唯一ID:&nbsp;&nbsp;</span></label>
                                        <input type="text" placeholder="**必填" id="edit_id" readonly="readonly"/>
                                    </div>
                                    <div>
                                        <label><span>资产编号</span></label>
                                        <input type="text" placeholder="**必填" id="edit_number"/>
                                    </div>
                                    <div>
                                        <textarea rows="10" cols="32" id="dismessage" readonly="readonly">详情信息:&#13;</textarea>
                                    </div>

                                </div>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default btn-sm" data-dismiss="modal">取消</button>
                                <button type="button" class="btn btn-primary btn-sm" data-dismiss="modal" onclick="editUser()">保存</button>
                            </div>
                        </div>
                    </div>
                </div>

</body>
{% endblock %}
{% block script %}

    $('#edit').on('show.bs.modal', function (event) {
        document.getElementById("dismessage").value = "";
        var button = $(event.relatedTarget) // Button that triggered the modal
        var recipient = button.data('whatever');// Extract info from data-* attributes
        document.getElementById("edit_id").value = document.getElementById(""+recipient+"_0").innerText;
        document.getElementById("edit_number").value = document.getElementById(""+recipient+"_1").innerText;
        $.post("{% url 'computerstatus:getauto' %}",{'id':recipient},function(data,status){
            if (data.code =="404"){
                alert(data.number)
            }
            else{
                for(var key in data.number){
                    document.getElementById("dismessage").value += " " + key + ":"
                    document.getElementById("dismessage").value += data.number[key]
                    document.getElementById("dismessage").value += "\n";
                }
            }

    })
    });

    function editUser(){
        var number = document.getElementById("edit_id").value
        var it_number = document.getElementById("edit_number").value
        if (it_number != ""){
            $.post("{% url 'computerstatus:auto' %}",{'id':number,'it_number':it_number},function(data,status){
                window.location.reload(data)
            })
        }
    }

{% endblock script %}